/**
 * 工具函数
 */
require("../../fonts/iconfont.css")

const BASE_URL = "http://139.9.177.51:8099";
function isPhone(num) {
    return /^1[3-9]\d{9}$/.test(num)
}

function isPassword(pwd) {
    return /^[a-zA-Z0-9_]{6,12}$/.test(pwd);
}

/*封装弹框提示 */
function toast(type = "duigou", msg = "操作成功", time = 3000) {
    let div = document.createElement("div")
    div.className = "toast-container"
    div.innerHTML = `
    <span class="iconfont icon-${type}"></span>
    <p class="mt8">${msg}</p>
    `
    document.body.appendChild(div)
    window.setTimeout(function () {
        div.remove();
    }, time)
}

/*封装一个底部生成函数*/
function addTabbar(currentPage) {
    let div = document.createElement("div")
    div.className = "footer-tabbar"
    div.innerHTML = `
    <a href="./index.html" class="tabber-item ${currentPage ==="index"?"active":""}">
        <span class="iconfont icon-shouye"></span>
    <p>首页</p>
    <a href="./sports.html" class="tabber-item ${currentPage ==="sports"?"active":""}">
        <span class="iconfont icon-yundong"></span>
    <p>运动</p>
    <a href="./min.html" class="tabber-item ${currentPage ==="min"?"active":""}">
        <span class="iconfont icon-wode"></span>
    <p>我的</p>
    </a>
    `
    document.querySelector("#footer").appendChild(div)
}

window.$utils = {
    isPhone: isPhone,
    isPassword: isPassword,
    toast: toast,
    BASE_URL: BASE_URL,
    addTabbar: addTabbar,
}

